﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Shop.SystemSet.Services;
using Shop.SystemSet.Models;

namespace Shop.SystemSet.Controllers
{
    public class SystemSetController : Controller
    {
        Services.SystemSetAccess bll = new SystemSetAccess();
        // GET: SystemSet
        public ActionResult SystemRoleSetting()
        {
            string zNodes = "[";
            IList<Models.Shop_Module> ModuleInfo = bll.GetModuleInfo();
            IList<Shop_Module> ParentMCodeInfo = new List<Shop_Module>();
            for (int i = 0; i < ModuleInfo.Count; i++)
            {
                if (string.IsNullOrEmpty(ModuleInfo[i].ParentMCode))
                {
                    ParentMCodeInfo.Add(ModuleInfo[i]);
                    zNodes += string.Format("{0} id: {1}, pId: 0, name: \"{2}\"{3},", "{", ModuleInfo[i].MID, ModuleInfo[i].MName, "}");
                }
            }

            for (int i = 0; i < ModuleInfo.Count; i++)
            {
                if (!string.IsNullOrEmpty(ModuleInfo[i].ParentMCode))
                {

                }
                for (int s = 0; s < ParentMCodeInfo.Count; s++)
                {
                    if (ModuleInfo[i].ParentMCode == ParentMCodeInfo[s].MCode)
                    {
                        zNodes += string.Format("{0} id: {1}, pId: {2}, name: \"{3}\"{4},", "{", ModuleInfo[i].MID, ParentMCodeInfo[s].MID, ModuleInfo[i].MName, "}");
                        break;
                    }
                }
            }
            zNodes += "]";
            ViewBag.zNodes = zNodes;
            return View();
        }
    }
}